package com.qiuyang.controller;

import com.qiuyang.pojo.Blog;
import com.qiuyang.service.show.ShowBlogService;
import com.qiuyang.service.show.ShowTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ShowTypeController {

    @Autowired
    private ShowTypeService showTypeService;
    @Autowired
    private ShowBlogService showBlogService;



    @RequestMapping("/type")
    public String listBlog( Model model){
        model.addAttribute("type",showTypeService.findAllType());
        model.addAttribute("blog",showBlogService.findAllBlog());
        return "blog/type";
    }

    @RequestMapping("/types/{id}")
    public String typeBlog(@PathVariable Long id,Model model){

        List<Blog> blogByType = showTypeService.findBlogByType(id);
        model.addAttribute("type",showTypeService.findAllType());
        model.addAttribute("blog",blogByType);

        return "blog/type";
    }
}
